package main


import (
    "fmt"
    "unicode/utf8"
)


func main(){
    s := "Yes 寇浩哲!"//UTF-8编码
    fmt.Println("s", s)
    for _, b := range []byte(s) {
        fmt.Printf("%X ", b)
    }
    fmt.Println()

    for i, ch := range s {//ch is a rune 
        fmt.Printf("(%d %X)", i, ch)
    }
    fmt.Println()
    
    fmt.Println("Rune count:", utf8.RuneCountInString(s))
    

    //一个字符一个字符拿出来
    bytes := []byte(s)
    for len(bytes) > 0 {
        ch, size := utf8.DecodeRune(bytes)// 返回字符和字符size 英文是1中文是3
        bytes = bytes[size:]
        fmt.Printf("%c ", ch)
    }
    fmt.Println()

    for i, ch := range []rune(s) {
        fmt.Printf("  %d,%c ", i, ch)
    }
    fmt.Println()
}












